package com.chen.Dome5_synchronized_method;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Account {
    private String cardId;
    private double balance;

    public synchronized void drawmoney(double money) {
        String name = Thread.currentThread().getName();
        //判断余额是否充足
        if (balance >= money) {
            System.out.println(name + "取款成功，取款金额：" + money);
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            balance -= money;
            System.out.println("余额为：" + balance);
        } else {
            System.out.println(name + "取款失败，余额不足");
        }
    }
}
